//
//  DKOrderIssueFailedCell.m
//  DanKU
//
//  Created by EDY on 2023/11/5.
//

#import "DKOrderIssueFailedCell.h"
#import "OrderTool.h"
#import "DKMainBankCardController.h"

@interface DKOrderIssueFailedCell()

@property(nonatomic,strong)UIView *dk_OrderCellView;
@property(nonatomic,strong)UIImageView *dk_OrderIcon_BackImg;
@property(nonatomic,strong)UIImageView *dk_OrderIconImg;
@property(nonatomic,strong)UILabel *dk_OrderTitlelab;
@property(nonatomic,strong)UILabel *dk_OrderStatelab;
//@property(nonatomic,strong)UIButton *dk_OrderInfoBtn;
@property(nonatomic,strong)UILabel *dk_OrderLine;
@property(nonatomic,strong)UILabel *dk_OrderCountlab;
@property(nonatomic,strong)UILabel *dk_OrderDatelab;
@property(nonatomic,strong)UILabel *dk_OrderCountStatelab;
@property(nonatomic,strong)UILabel *dk_OrderCountInfolab;

@property(nonatomic,strong)UIImageView *dk_OrderIssBackImg;
@property(nonatomic,strong)UIImageView *dk_OrderIssLeftIssImg;
@property(nonatomic,strong)UILabel *dk_OrderIssContextLab;
@property(nonatomic,strong)UIButton *dk_OrderIssBtn;

@end

@implementation DKOrderIssueFailedCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor =  DK_Hex(@"#FAFAFA");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self creatUI];
    }
    return  self;
}

-(void)setDateSouce:(DKOrderRecordListModel *)dateSouce{
    self.dk_OrderTitlelab.text = dateSouce.productName;
    self.dk_OrderStatelab.text = @"Issue failed";
    self.dk_OrderStatelab.textColor = DK_Hex(@"#FF0000");
//    self.dk_OrderInfoBtn.hidden  = YES;
    
    DKBeforePaymentDetail *model = dateSouce.beforePaymentDetail;
    self.dk_OrderCountlab.text = [OrderTool formatAmountForIndia:model.loanAmount];
    
    NSString  *formattedDateString = [OrderTool convertDate:[OrderTool stringFromTimestampString:model.applyTime] fromFormat:@"yyyy-MM-dd HH:mm:ss" toFormat:@"dd-MM-yyyy"];
    self.dk_OrderDatelab.text = formattedDateString;
    
}

-(void)creatUI{
    [self.contentView addSubview:self.dk_OrderCellView];
    [self.dk_OrderCellView addSubview:self.dk_OrderIcon_BackImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderIconImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderTitlelab];
    [self.dk_OrderCellView addSubview:self.dk_OrderStatelab];
//    [self.dk_OrderCellView addSubview:self.dk_OrderInfoBtn];
    [self.dk_OrderCellView addSubview:self.dk_OrderLine];
    [self.dk_OrderCellView addSubview:self.dk_OrderCountlab];
    [self.dk_OrderCellView addSubview:self.dk_OrderDatelab];
    [self.dk_OrderCellView addSubview:self.dk_OrderCountStatelab];
    [self.dk_OrderCellView addSubview:self.dk_OrderCountInfolab];
    
    [self.dk_OrderCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.top.equalTo(self.contentView).offset(5);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    
    [self.dk_OrderIcon_BackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.width.height.mas_equalTo(38);
        make.top.equalTo(self.dk_OrderCellView).offset(12);
    }];
    
    [self.dk_OrderIconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(26);
        make.center.equalTo(self.dk_OrderIcon_BackImg);
    }];

    [self.dk_OrderTitlelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg.mas_right).offset(5);
        make.width.mas_equalTo(DK_SCREEN_W/3);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(self.dk_OrderIcon_BackImg);
    }];

    [self.dk_OrderStatelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.dk_OrderCellView.mas_right).offset(-20);
        make.width.height.equalTo(self.dk_OrderTitlelab);
        make.centerY.equalTo(self.dk_OrderIcon_BackImg);
    }];

//    [self.dk_OrderInfoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.dk_OrderCellView.mas_right).offset(-15);
//        make.width.height.mas_equalTo(16);
//        make.centerY.equalTo(self.dk_OrderIcon_BackImg);
//    }];

    [self.dk_OrderLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.right.equalTo(self.dk_OrderCellView).offset(-15);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.dk_OrderIcon_BackImg.mas_bottom).offset(10);
    }];

    [self.dk_OrderCountlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg);
        make.width.height.equalTo(self.dk_OrderTitlelab);
        make.top.equalTo(self.dk_OrderLine.mas_bottom).offset(20);
    }];

    [self.dk_OrderDatelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.dk_OrderCellView).offset(-15);
        make.width.height.top.equalTo(self.dk_OrderCountlab);
    }];

    [self.dk_OrderCountStatelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.left.equalTo(self.dk_OrderCountlab);
        make.top.equalTo(self.dk_OrderCountlab.mas_bottom).offset(10);
    }];

    [self.dk_OrderCountInfolab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.right.equalTo(self.dk_OrderDatelab);
        make.top.equalTo(self.dk_OrderCountStatelab);
    }];
    
    [self.dk_OrderCellView addSubview:self.dk_OrderIssBackImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderIssLeftIssImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderIssContextLab];
    [self.dk_OrderCellView addSubview:self.dk_OrderIssBtn];
    
    [self.dk_OrderIssBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(10);
        make.right.equalTo(self.dk_OrderCellView).offset(-10);
        make.height.mas_equalTo(55);
        make.top.equalTo(self.dk_OrderCountStatelab.mas_bottom).offset(20);
    }];
    
    [self.dk_OrderIssLeftIssImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(18);
        make.left.equalTo(self.dk_OrderIssBackImg).offset(20);
        make.centerY.equalTo(self.dk_OrderIssBackImg);
    }];
    
    [self.dk_OrderIssContextLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIssLeftIssImg.mas_right).offset(10);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(45);
        make.centerY.equalTo(self.dk_OrderIssBackImg);
    }];
    
    [self.dk_OrderIssBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(75);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.dk_OrderIssBackImg);
        make.right.equalTo(self.dk_OrderCellView).offset(-20);
    }];
}

#pragma mark - 详情
-(void)listinfo{
    DKMainBankCardController *dk_MainBankCardCtrl = [[DKMainBankCardController alloc] init];
    [[self viewController].navigationController pushViewController:dk_MainBankCardCtrl animated:YES];
}


#pragma mark - 懒加载
-(UIView*)dk_OrderCellView{
    if (!_dk_OrderCellView) {
        _dk_OrderCellView = [[UIView alloc]init];
        _dk_OrderCellView.backgroundColor = DK_Hex(@"#FFFFFF");
        _dk_OrderCellView.layer.cornerRadius = 10;
    }
    return _dk_OrderCellView;
}

- (UIImageView*)dk_OrderIcon_BackImg{
    if (!_dk_OrderIcon_BackImg) {
        _dk_OrderIcon_BackImg = [[UIImageView alloc] init];
        _dk_OrderIcon_BackImg.image =  DK_GetImage(@"dk_order_list_back_img");
    }
    return _dk_OrderIcon_BackImg;
}

- (UIImageView*)dk_OrderIconImg{
    if (!_dk_OrderIconImg) {
        _dk_OrderIconImg = [[UIImageView alloc] init];
        _dk_OrderIconImg.image =  DK_GetImage(@"dk_order_list_img");
    }
    return _dk_OrderIconImg;
}

- (UILabel *)dk_OrderTitlelab {
    if (!_dk_OrderTitlelab) {
        _dk_OrderTitlelab = [[UILabel alloc] init];
        _dk_OrderTitlelab.textColor = DK_Hex(@"#333333");
        _dk_OrderTitlelab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderTitlelab.text = @"Go 002";
    }
    return _dk_OrderTitlelab;
}


- (UILabel *)dk_OrderStatelab {
    if (!_dk_OrderStatelab) {
        _dk_OrderStatelab = [[UILabel alloc] init];
        _dk_OrderStatelab.textColor = DK_Hex(@"#333333");
        _dk_OrderStatelab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderStatelab.text = @"Under review";
        _dk_OrderStatelab.textAlignment = 2;
    }
    return _dk_OrderStatelab;
}

//-(UIButton*)dk_OrderInfoBtn{
//    if (!_dk_OrderInfoBtn) {
//        _dk_OrderInfoBtn = [[UIButton alloc]init];
//        [_dk_OrderInfoBtn addTarget:self action:@selector(listinfo) forControlEvents:UIControlEventTouchUpInside];
//        [_dk_OrderInfoBtn setBackgroundImage:[UIImage imageNamed:@"icon_my_next_b"] forState:UIControlStateNormal];
//        [_dk_OrderInfoBtn setBackgroundImage:[UIImage imageNamed:@"icon_my_next_b"] forState:UIControlStateSelected];
//    }
//    return _dk_OrderInfoBtn;
//}

- (UILabel *)dk_OrderLine {
    if (!_dk_OrderLine) {
        _dk_OrderLine = [[UILabel alloc] init];
        _dk_OrderLine.backgroundColor = DK_Hex(@"#E0E0E0");
    }
    return _dk_OrderLine;
}

- (UILabel *)dk_OrderCountlab {
    if (!_dk_OrderCountlab) {
        _dk_OrderCountlab = [[UILabel alloc] init];
        _dk_OrderCountlab.textColor = DK_Hex(@"#333333");
        _dk_OrderCountlab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderCountlab.text = @"₹3,000";
    }
    return _dk_OrderCountlab;
}

- (UILabel *)dk_OrderDatelab {
    if (!_dk_OrderDatelab) {
        _dk_OrderDatelab = [[UILabel alloc] init];
        _dk_OrderDatelab.textColor = DK_Hex(@"#333333");
        _dk_OrderDatelab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderDatelab.textAlignment = 2;
        _dk_OrderDatelab.text = @"18-07-2022";
    }
    return _dk_OrderDatelab;
}

- (UILabel *)dk_OrderCountStatelab {
    if (!_dk_OrderCountStatelab) {
        _dk_OrderCountStatelab = [[UILabel alloc] init];
        _dk_OrderCountStatelab.textColor = DK_Hex(@"#999999");
        _dk_OrderCountStatelab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderCountStatelab.text = @"Loan amount";
    }
    return _dk_OrderCountStatelab;
}

- (UILabel *)dk_OrderCountInfolab {
    if (!_dk_OrderCountInfolab) {
        _dk_OrderCountInfolab = [[UILabel alloc] init];
        _dk_OrderCountInfolab.textColor = DK_Hex(@"#999999");
        _dk_OrderCountInfolab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderCountInfolab.textAlignment = 2;
        _dk_OrderCountInfolab.text = @"Application data";
    }
    return _dk_OrderCountInfolab;
}


-(UIImageView*)dk_OrderIssBackImg{
    if (!_dk_OrderIssBackImg) {
        _dk_OrderIssBackImg = [[UIImageView alloc]init];
        _dk_OrderIssBackImg.image = DK_GetImage(@"oeder_rectangle");
        _dk_OrderIssBackImg.layer.cornerRadius = 20;
    }
    return _dk_OrderIssBackImg;
}


- (UIImageView*)dk_OrderIssLeftIssImg{
    if (!_dk_OrderIssLeftIssImg) {
        _dk_OrderIssLeftIssImg = [[UIImageView alloc] init];
        _dk_OrderIssLeftIssImg.image =  DK_GetImage(@"order_warning_big");
    }
    return _dk_OrderIssLeftIssImg;
}

- (UILabel *)dk_OrderIssContextLab {
    if (!_dk_OrderIssContextLab) {
        _dk_OrderIssContextLab = [[UILabel alloc] init];
        _dk_OrderIssContextLab.textColor = DK_Hex(@"#000000");
        _dk_OrderIssContextLab.font = [UIFont boldSystemFontOfSize:14];
        _dk_OrderIssContextLab.text = @"Please check your bank\naccount and reapply";
        _dk_OrderIssContextLab.numberOfLines = 0;
    }
    return _dk_OrderIssContextLab;
}

-(UIButton*)dk_OrderIssBtn{
    if (!_dk_OrderIssBtn) {
        _dk_OrderIssBtn = [[UIButton alloc]init];
        [_dk_OrderIssBtn addTarget:self action:@selector(listinfo) forControlEvents:UIControlEventTouchUpInside];
        [_dk_OrderIssBtn setBackgroundImage:[UIImage imageNamed:@"Order_rectangel_button"] forState:UIControlStateNormal];
        [_dk_OrderIssBtn setBackgroundImage:[UIImage imageNamed:@"Order_rectangel_button"] forState:UIControlStateSelected];
        [_dk_OrderIssBtn setTitle:@"To modify" forState:UIControlStateNormal];
        _dk_OrderIssBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_dk_OrderIssBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
        _dk_OrderIssBtn.layer.cornerRadius = 5;
        _dk_OrderIssBtn.layer.maskedCorners = YES;
    }
    return _dk_OrderIssBtn;
}

//获取View所在的Viewcontroller方法
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

@end
